
////////////////////////////////////////////////////////////////////////////////
//
// Main.java
//
// Copyright © (C) 2010
// 
// Emory Hughes Merryman, III
// emory.merryman@gmail.com
// 
// All Rights Reserved
// 
// This file is part of Interworks.
// 
// Interworks is free software: you can 
// redistribute it and/or modify it under 
// the terms of the GNU General Public 
// License as published by the Free 
// Software Foundation, either version 3 
// of the License, or (at your option) any 
// later version.
// 
// This program is distributed in the hope 
// that it will be useful, but WITHOUT 
// ANY WARRANTY; without even the 
// implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR 
// PURPOSE.  See the GNU General Public 
// License for more details.
//
// You should have received a copy of the 
// GNU General Public License along with 
// this program.  If not, see 
// <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////////////

package com . superiorglobalbusiness . researchr ;

import java . util . concurrent . Callable ;
import java . sql . Driver ;
import java . sql . DriverManager ;
import javax . sql . DataSource ;
import org . apache . commons . logging . Log ;
import org . apache . commons . logging . LogFactory ;
import
    org . springframework . jdbc . datasource .
    SimpleDriverDataSource ;
import org . springframework . context . ApplicationContext ;
import
    org . springframework . context . annotation .
    AnnotationConfigApplicationContext ;
import org . springframework . context . annotation . Bean ;

import java . sql . SQLException ;

final class Main implements Callable < Void >
{
    private static final int NUMBER_OF_TRIALS = 100 ;

    private static final int SIZE_OF_ARRAY = 100000 ;

    private static final int SAMPLE_SIZE = 1 ;

    private Log log_ = LogFactory . getLog ( this . getClass ( ) ) ;

    private Main ( )
    {
	super ( ) ;
    }

    @ Override
	public Void call ( ) throws Exception
    {
	ApplicationContext context =
	    new AnnotationConfigApplicationContext
	    ( Main . class , DAO .class , JavaSum . class , RSum . class ) ;
	String [ ] beans = context . getBeanDefinitionNames ( ) ;
	for ( String bean : beans )
	    {
		log_ . warn ( bean ) ;
	    }
	DAO dao = context . getBean ( DAO . class ) ;
	Sum c =
	    ( Sum )
	    context . getBean ( "RSum" , NUMBER_OF_TRIALS , SIZE_OF_ARRAY ) ;
	dao . record ( c , SAMPLE_SIZE ) ; 
	dao . results ( ) ;
	return ( null ) ;
    }

    @ Bean
	DataSource dataSource ( ) throws SQLException
    {
	Driver driver = new com . mysql . jdbc . Driver ( ) ;
	DriverManager . registerDriver ( driver ) ;
	String url = System . getProperty ( "url" ) ;
	String username = System . getProperty ( "username" ) ;
	String password = System . getProperty ( "password" ) ;
	DataSource dataSource =
	    new SimpleDriverDataSource ( driver , url , username , password ) ; 
	return dataSource ;
    }

    public static void main ( final String [ ] args ) throws Exception
    {
	Callable < Void > callable = new Main ( ) ;
	callable . call ( ) ;
    }
}
